﻿Public Class DaoHanghoa
    Public Shared Function Them(ByVal ma As String, ByVal tenH As String, ByVal qcach As String, ByVal gia As Double, ByVal slton As Integer) As String
        Dim err As String = String.Empty
        Try
            Dim data As New DataProvider
            Dim query As String = "insert into HangHoa values('" & ma & "',N'" & tenH & "',N'" & qcach & "','" & gia & "','" & slton & "')"
            data.ExecuteQuery(query)
        Catch ex As Exception
            err = ex.Message.ToString()
        End Try       
        Return err
    End Function
    Public Shared Function Lay() As DataTable
        Dim bang As DataTable = Nothing
        Try
            Dim data As New DataProvider
            Dim query As String = "select * from HangHoa"
            bang = data.ExecuteQuery(query)
        Catch ex As Exception
            Throw New Exception(ex.Message.ToString())
        End Try
        Return bang
    End Function
    Public Shared Function Xoa(ByVal ma As String) As String
        Dim err As String = String.Empty
        Try
            Dim data As New DataProvider
            Dim query As String = "Delete from HangHoa where Mahh='" & ma & "'"
            data.ExecuteQuery(query)


        Catch ex As Exception
            err = ex.Message.ToString()
        End Try
        Return err

    End Function
    Public Shared Function Capnhat(ByVal ma As String, ByVal ten As String, ByVal qc As String, ByVal gia As Double, ByVal soluong As Integer) As String
        Dim err As String = String.Empty
        Try
            Dim data As New DataProvider
            Dim query As String = "update HangHoa set Tenhh=N'" & ten & "',Quycach= N'" & qc & "',Giaban='" & gia & "',Slton='" & soluong & "' where Mahh='" & ma & "'"
            data.ExecuteQuery(query)
        Catch ex As Exception
            err = ex.Message.ToString()
        End Try
        Return err
    End Function
End Class
